package com.example.bishe.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bishe.entity.Record;
import com.example.bishe.entity.RecordChildren;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.bishe.web.c.dto.AddRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LDH
 * @since 2022/11/30
 */
@Mapper
public interface RecordChildrenMapper extends BaseMapper<RecordChildren> {

    @Select("SELECT * FROM `record_children` WHERE to_days(create_time)=to_days(now()) AND record_id=#{recordId}")
    List<RecordChildren> selectByTime(@Param("recordId") Long recordId);

    @Select("SELECT * FROM `record_children` WHERE state=0 AND record_id=#{recordId}")
    RecordChildren selectByState(@Param("recordId") Long recordId);

    IPage<AddRecord> getPage(
            IPage<RecordChildren> page,
            @Param("time") String time,
            @Param("recordId") Long recordId,
            @Param("show") Integer show
    );

    @Select("SELECT * FROM record_children WHERE record_id=#{recordId} AND create_time >= #{start} AND create_time < #{end}")
    List<RecordChildren> getCalendar(@Param("recordId") Long recordId, @Param("start") String start, @Param("end") String end);

    IPage<RecordChildren> getBarPage(
            IPage<RecordChildren> page,
            @Param("recordId") Long recordId,
            @Param("show") Integer show
    );

}
